package com.example.uilearning;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.ToggleButton;

public class ToggleAndSwitchActivity extends Activity {
   private LinearLayout linearLayout;
   private ToggleButton toggleButton;
   private Switch switchButton;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_toggle_and_switch);
		linearLayout=(LinearLayout)findViewById(R.id.layout);
		toggleButton=(ToggleButton)findViewById(R.id.toggleButton);
		switchButton=(Switch)findViewById(R.id.switchButton);
		OnCheckedChangeListener coCheckedChangeListener=new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked){
					linearLayout.setOrientation(1);
				}else{
					linearLayout.setOrientation(0);
				}
			}
		};
		toggleButton.setOnCheckedChangeListener(coCheckedChangeListener);
		switchButton.setOnCheckedChangeListener(coCheckedChangeListener);
	}
}
